package com.yeyks.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeyks.config.dal.dao.WebConfigurationMapper;
import com.yeyks.config.dal.domain.WebConfiguration;
import com.yeyks.config.pojo.param.WebConfigurationSystemVersionParam;
import com.yeyks.config.service.WebConfigurationService;
import org.springframework.stereotype.Service;

import java.util.Objects;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-11-27
 */
@Service
public class WebConfigurationServiceImpl extends ServiceImpl<WebConfigurationMapper, WebConfiguration> implements WebConfigurationService {

    @Override
    public String getValue(WebConfigurationSystemVersionParam param) {
        WebConfiguration webConfiguration = baseMapper.selectOne(
                new QueryWrapper<WebConfiguration>()
                        .eq(WebConfiguration.CONFIG_KEY, param.getKey())
                        .eq(Objects.nonNull(param.getVersion()), WebConfiguration.VERSION, param.getVersion())
                        .orderByDesc(WebConfiguration.VERSION)
                        .last("limit 1")
        );
        if (Objects.nonNull(webConfiguration)) {
            return webConfiguration.getConfigValue();
        }
        return "";
    }

}
